package helper.base

typealias DoubleRange = ClosedFloatingPointRange<Double>
typealias RangeTuple<E> = A2Tuple<DoubleRange, E>
typealias RangeTupleListTuple<E> = A2Tuple<ArrayList<RangeTuple<E>>, Double>

object RangeHelper {
    object Expand {
        private fun <E> RangeTupleListTuple<E>.getRandomObjOrNull(
        ): E? {
            // 按照每个事件及其区间的权重随机选择一个事件
            val randomValue = RandomHelper.getRandomDouble(second)
            return first.find { (range, _) ->
                randomValue in range
            }?.second
        }

        fun <E> RangeTupleListTuple<E>.getRandomObj(
        ): E {
            var result: E? = null

            while (result == null) {
                result = getRandomObjOrNull()
            }
            return result
        }
    }
}